#include"stdafx.h"
#include "DeleteProcess.h"

DeleteProcess::DeleteProcess(string cmdString,allTaskList *givenLists,allCommandStack *givenStacks):LogicProcess(cmdString,givenLists,givenStacks){
	needList=&allTask->getUpcomingTasks();
}
DeleteProcess::DeleteProcess(Task task,TaskList *list):LogicProcess(task,list){

}

void DeleteProcess::HandleProcesss(){
	int deleteIndex=cvtToNumber(commandString);//The display list start from 1
	//TaskList *needList=&allTask->getUpcomingTasks();
	if (canDelete(deleteIndex)){
		backupToUndo(deleteIndex);
		RemoveTask(needList,deleteIndex);
	}
	fromNeedtoDisplay();
}
bool DeleteProcess::canDelete(int index){
	bool result;
	result= index<=needList->getLength();
	return result;
}
void DeleteProcess::backupToUndo(int index){
	Task tmp;
	needList->retrieve(index,tmp);
	taskContainer contain=upcoming;
	commandType type=Add;
	pushToUndoList(tmp,type,contain,false);
}
void DeleteProcess::quickProcess(Task task){
	int deleteIndex;

	deleteIndex=needList->searchTask(task);

	//TaskList *needList=&allTask->getUpcomingTasks();
	RemoveTask(needList,deleteIndex);
}

bool DeleteProcess::RemoveTask(TaskList *needList,int deleteIndex){
	if (needList->getLength()>=deleteIndex){
		needList->remove(deleteIndex);
		return true;
	}
	return false;
}